<template>
  <div>
    <van-icon
      :color="value ? 'orange' : '#777'"
      :name="value ? 'star' : 'star-o'"
      @click="collectFn"
    />
  </div>
</template>

<script>
import { collectArticle, deletecollectArticle } from "@/api/article";
export default {
  // v-model组件之间的双向数据绑定
  props: ["value", "article_id"],
  methods: {
    async collectFn() {
      try {
        if (this.value) {
          // 取消收藏
          let re = await deletecollectArticle(this.article_id);
          this.$toast("取消成功");
          console.log(re);
        } else {
          //收藏
          let re = await collectArticle(this.article_id);
          this.$toast("收藏成功");
          console.log(re);
        }
        this.$emit("input", !this.value);
      } catch (error) {
        console.log(error);
      }
    },
  },
};
</script>

<style>
</style>